<template>
  <text>{{ label }}</text>
</template>

<script>
import dictUtil from '@/utils/dictUtil.js'

export default {
  name: 'DictLabel',
  props: {
    dictType: {
      type: String,
      required: true
    },
    value: {
      type: [String, Number, null],
      default: null
    }
  },
  data() {
    return {
      label: ''
    }
  },
  watch: {
    value: {
      handler: 'loadLabel',
      immediate: true
    },
    dictType: {
      handler: 'loadLabel',
      immediate: true
    }
  },
  methods: {
    async loadLabel() {
      if (this.value === null || this.value === undefined || this.value === '') {
        this.label = ''
        return
      }
      this.label = await dictUtil.formatDictLabel(this.dictType, this.value)
    }
  }
}
</script>
